﻿using HarmonyLib;
using RimWorld;
using System;
using System.Reflection;
using Verse;

namespace RimZombieGirl
{
    public class HARPatcher
    {
        //This class exists because it's not possible to instantiate it without HAR installed
        // C# runtime hates the reference to AlienRace stuff in here
        public static void patch()
        {
            // 检查 AlienRace mod 是否已加载
            if (!ModsConfig.IsActive("erdelf.HumanoidAlienRaces"))
            {
                Log.Warning("[ZombieGirl] 未检测到 Humanoid Alien Races (HAR) mod，跳过 HAR Patch。");
                return;
            }
            Harmony harmony = new Harmony("ZombieGirl.HARPatch");
            try
            {
                ((Action)(() =>
                {
                    harmony.Patch((MethodBase)AccessTools.Method(typeof(AlienRace.AlienRenderTreePatches), "BodyGraphicForPrefix"), prefix: new HarmonyMethod(typeof(ZGPatches.ZGBodyGraphicForPrefixHARPrefix), "Prefix"));
                    harmony.Patch((MethodBase)AccessTools.Method(typeof(AlienRace.AlienRenderTreePatches), "HeadGraphicForPrefix"), prefix: new HarmonyMethod(typeof(ZGPatches.ZGHeadGraphicForPrefixHARPrefix), "Prefix"));
                }))();
            }
            catch (TypeLoadException e)
            {
                Log.Error("[ZombieGirl] TypeLoadException:");
                Log.Error(e.StackTrace);
            }
        }
    }

}
